package me.sunsy.kit.proxy.inter

import java.lang.reflect.Method

interface Schedu {

    fun exec(str: String)

}

class ScheduImpl : Schedu {
    override fun exec(str: String) {
        println("任务执行中，参数为 $str")
    }

}

interface MyPlugin {
    fun interceptor(myInvocation: MyInvocation): Any?
}


class MyPluginOne : MyPlugin {
    override fun interceptor(myInvocation: MyInvocation): Any? {
        println("--插件1")
        var o = myInvocation.TestInterceptor()
        println("插件1结束了")
        return o
    }
}

class MyPluginTwo : MyPlugin {

    override fun interceptor(myInvocation: MyInvocation): Any? {
        println("--插件2")
        var o = myInvocation.TestInterceptor()
        println("--插件2结束了")
        return o
    }

}

interface MyInvocation {
    fun TestInterceptor(): Any?
}

class MyInvocationTest : MyInvocation {
    private var obj: Any
    private var args: Array<Any>
    private var method: Method

    constructor(obj: Any, method: Method, plugin: Array<Any>) {
        this.obj = obj
        this.args = plugin
        this.method = method
    }

    override fun TestInterceptor(): Any? {
        return method.invoke(obj, *args)
    }

}